let arr = [1,2,3,4];
function pailie(list, prefix) {
    console.log(list, prefix);
    let result = [];
    for (let i = 0; i < list.length; i++) {
        let temp = [...prefix, list[i]]
        result = result.concat(pailie(list.slice(i + 1), temp));
        result.push(temp);
    }
    return result;
}
console.log(pailie(arr, []));